home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15836 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.8 KB  |  81 lines

  1. Path: lrz-muenchen.de!news
  2. From: "A. Sander" <pa101aa@sunmail.lrz-muenchen.de>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Virtual Inheritance
  5. Date: Mon, 08 Apr 1996 10:43:05 +0200
  6. Organization: none
  7. Distribution: world
  8. Message-ID: <3168D199.7470@sunmail.lrz-muenchen.de>
  9. References: <4k9tpv$173k@news-s01.ny.us.ibm.net>
  10. NNTP-Posting-Host: dial037.ppp.lrz-muenchen.de
  11. Mime-Version: 1.0
  12. Content-Type: text/plain; charset=us-ascii
  13. Content-Transfer-Encoding: 7bit
  14. X-Mailer: Mozilla 2.01 (WinNT; I)
  15.  
  16. bbogard@ibm.net wrote:
  17. > I was recently talking to a possible employer on the phone, and he asked me a question
  18. > about C++ I had never heard of before.  He has me what is virtual inheritance?  Is this
  19. > an ANSI compatible extension or something.  I have used a number of compilers including
  20.  
  21. it's (or say, will be) ANSI.
  22.  
  23. > VC 4.1 and BC 4.5 and neither of those had virtual inheritance defined in the language.
  24.  
  25. wrong, they have.
  26.  
  27. > What is it, and what is it used for?
  28.  
  29. My (negative) opinion about virtual inhertance follows:
  30.  
  31. Well, virtual inheritance is only ... wah! only a workaround
  32. for a common problem occuring using multiple inheritance.
  33.  
  34. If you use multiple inheritance in following example:
  35.  
  36. class base
  37. {};
  38. class a : public base
  39. {};
  40. class b : public base
  41. {}
  42. class c : public a, public b
  43. {};
  44.  
  45. you will get:
  46.  
  47.    base base
  48.      \  /
  49.      a  b
  50.       \/
  51.       c
  52.  
  53. and here starts the problem, that in most cases you don't need
  54. that duplicated base-class. With virtual inheritance:
  55.  
  56. class base
  57. {};
  58. class a : virtual public base
  59. {};
  60. class b : virtual public base
  61. {}
  62. class c : public a, public b
  63. {};
  64.  
  65. you get the expected result:
  66.  
  67.      base
  68.       /\
  69.      a  b
  70.       \/
  71.       c
  72.  
  73.  
  74. I personally have tried to use virtual inheritance in several
  75. ways. But in fact I was never successful building class hierarchies
  76. using multiple/virtual inheritance.
  77.  
  78. ciao,
  79.   Armin
  80.